/*
 * Tester.java
 *
 * Created on November 9, 2008, 6:55 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package jollylengkono.skripsi.tester;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import jollylengkono.skripsi.model.Subjects;

/**
 *
 * @author JollkY
 */
public class Tester {

    private EntityManagerFactory emf = Persistence.createEntityManagerFactory("kmPU");

    private EntityManager em = emf.createEntityManager();
    
    /** Creates a new instance of Tester */
    public Tester() {
    }
    
    public static void main(String[] args) {
        Subjects s = new Subjects();
        s.setName("Management");
        s.setDescription("Management proses.");
        new Tester().persist(s);
        
//        List<String> tes = new ArrayList<String>();
//        tes.add("a");
//        tes.add("b");
//        tes.add("c");
//        Iterator iter = tes.iterator();
//        while(iter.hasNext()) {
//            String a = (String) iter.next();
//            System.out.println(a);
//        }
    }

    public void persist(Object object) {
        try {
            em.getTransaction().begin();
            // TODO:
            em.persist(object);    em.getTransaction().commit();
        } catch(Exception e) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE,"exception caught", e);
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
    }
    
}
